﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Dangkylop : System.Web.UI.Page
{
    BUS_ChildrenClass objC = new BUS_ChildrenClass();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["AdminLogin"] != null)
            {
                Page.Title = "Đăng Ký Lớp";
                LoadData();
            }
            else Response.Redirect("dangnhap.aspx");

        }
    }
    public void LoadData()
    {
        gvdklop.DataSource = objC.ChildrenClass_getAllData();
        gvdklop.DataBind();
    }
    protected void btnxoadk_Click(object sender, EventArgs e)
    {
        try
        {
            int count = 0;
            for (int i = 0; i < gvdklop.Rows.Count; i++)
            {
                CheckBox chk = (CheckBox)gvdklop.Rows[i].Cells[0].FindControl("chkdk");
                if (chk.Checked)
                {
                    count++;
                    int id = int.Parse(gvdklop.Rows[i].Cells[1].Text);
                    //lap danh sach xoa
                    objC.ChildrenClass_addtodel(id);
                }
            }
            //tien hanh xoa
            if (count > 0)
            {
                if (objC.ChildrenClass_del())
                {
                    LoadData();
                }
                else
                {
                    Response.Write("<script>alert(\"Xóa không thành công\")</script>");
                }
            }
            else Response.Write("<script>alert(\"Bạn chưa chọn mục xóa\")</script>");

        }
        catch (Exception ex)
        {

            throw new Exception(ex.Message);
        }
    }
    protected void gvdklop_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvdklop.PageIndex = e.NewPageIndex;
        LoadData();
    }

    protected void gvdklop_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("style", "background-color: #fff ; color: #000;");
                e.Row.Attributes.Add("onmouseover", "style.backgroundColor='#ccc'");
                e.Row.Attributes.Add("onmouseout", "style.backgroundColor='#fff'");
            }
        }
        catch { }
    }
}